package com.shudes.pt.builder;

import java.util.*;

import org.hibernate.*;
import org.hibernate.criterion.*;

import com.shudes.pt.db.*;
import com.shudes.pt.pojo.*;

public class PlayerBuilder {

	protected SessionContext context;
	
	public PlayerBuilder(SessionContext context) {
		this.context=context;
	}
	
	public Player byName(String screenName) {
		Session session;
		List players; 
		
		session = context.getSession();
		session.beginTransaction();
		players = 
			session.createCriteria(Player.class).add(Restrictions.eq("screenName", screenName)).list();
		
//		System.out.println("byName -> " + players);
		session.getTransaction().commit();
		return ((players!=null && players.size()>0)) ? (Player) players.get(0) : null;
	}

}
